package org.pqsoft.pledgecontract.service;

import java.util.List;
import java.util.Map;

import com.mframework.system.BaseDao;
import com.mframework.system.PageTemplate;

public class ContractGeneral {
	BaseDao<?> dao = new BaseDao();

	public PageTemplate list(Map<String, Object> param) {
		BaseDao<?> dao = BaseDao.newInstance();
		int pageCurr = 1;
		int pageCount = 10;
		if (!(param.get("PAGE_CURR") == null || "".equals(param
				.get("PAGE_CURR").toString().trim()))) {
			pageCurr = Integer.parseInt(param.get("PAGE_CURR").toString());
		}
		if (!(param.get("PAGE_COUNT") == null || "".equals(param.get(
				"PAGE_COUNT").toString().trim()))) {
			pageCount = Integer.parseInt(param.get("PAGE_COUNT").toString());
		}
		param.put("PAGE_BEGIN", pageCount * (pageCurr - 1) + 1);
		param.put("PAGE_END", pageCount * pageCurr);
		List<?> list = dao.selectForList(param.get("xml") + ".list", param);
		int count = dao.selectForInteger(param.get("xml") + ".list_count",
				param);
		PageTemplate pt = new PageTemplate(list, pageCurr, pageCount, count, 5);
		return pt;
	}

	public Map<String, Object> select(Map<String, Object> parama) {
		Map<String, Object> map = (Map<String, Object>) dao.selectForOne(parama
				.get("xml")
				+ "select", parama);
		return map;
	}

	public List<Map<String, Object>> select1(Map<String, Object> parama) {
		List<Map<String, Object>> lst = (List<Map<String, Object>>) dao
				.selectForList(parama.get("xml") + "select1", parama);
		return lst;
	}

	public int insert(Map<String, Object> param) {
		int a = dao.insert(param.get("xml") + "insert", param);
		return a;
	}

	public int update(Map<String, Object> param) {
		int a = dao.update(param.get("xml") + "update", param);
		return a;
	}
}